package com.umpay.controller.ebankpay;

import com.umpay.annotation.ReceiveEntity;
import com.umpay.business.ebankpay.EbankPayBusiness;
import com.umpay.controller.base.AbstractController;
import com.umpay.dto.merAccess.req.ebankpay.EbankPayReq;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @ClassName: EbankPayController  
 * @Description: 网银支付 
 * @author zhangtao  
 * @date May 26, 2018
 */
@RestController
public class EbankPayController  extends AbstractController {

	private static final Logger log = LogManager.getLogger(EbankPayController.class);
	
	@Autowired
	private EbankPayBusiness ebankPayBusinessImpl;
	
	@PostMapping("/payment/ebank")
	@ReceiveEntity(type = EbankPayReq.class)
	public ModelAndView bindcardOrder(HttpServletRequest request,HttpServletResponse response) {
		EbankPayReq ebankPayReq = getReqMessage(request);
		log.info(String.format("网银支付请求参数[%s]", ebankPayReq));
		return  ebankPayBusinessImpl.ebankPayOrder(ebankPayReq);
	}
	
	@GetMapping("/ebankpay/frontNotify")
    public ModelAndView h5FrontNotify(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> requestMap = getReqMessage(request);  
        log.info(String.format("网银支付前台通知结果为[%s]", requestMap));
        return ebankPayBusinessImpl.ebankPayFrontNotify(requestMap);
    }
    @GetMapping("/ebankpay/backNotify")
    public void h5BackNotify(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> requestMap = getReqMessage(request);  
        log.info(String.format("网银支付后台通知结果为[%s]", requestMap));
        ebankPayBusinessImpl.ebankPayBackNotify(requestMap, response);
    }
}
